package project.euler.honk.problem.to100;

import java.math.BigInteger;

public final class Problem56 {
	
	private static int getDigitalSum(BigInteger number) {
		char[] chars = number.toString().toCharArray();
		int sum = 0;
		for (int i = 0; i < chars.length; i++) {
			sum += chars[i] - '0';
		}
		return sum;
	}
	
	public static int solve() {
		int max = 0;		
		for(int a = 2; a < 100; a++) {
			BigInteger aVal = BigInteger.valueOf(a);
			BigInteger value = aVal;
			for(int b = 2; b < 100; b++) {
				value = value.multiply(aVal);
				max = Math.max(max, getDigitalSum(value));
			}
		}		
		return max;
	}
	
	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		int count = solve();
		long end = System.currentTimeMillis();
		System.out.println("Result: " + count + " Time: " + (end - start));
	}

}
